﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Linq;
using KeMei.Common;

public partial class Manager_Main : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserInfo"] == null)
        {
            Response.Redirect(ConfigHelper.SystemUrl + "Manager/login.aspx", true);
            
        }

        if (!IsPostBack)
        {
            this.initMenu();
            setUserInfo();

            lnkMidifyPwd.OnClientClick= Win_Pwd.GetShowReference("ChangePassword.aspx", "修改密码");
        }
    }

    protected void setUserInfo()
    {
        KeMei.Model.SysUser user = (KeMei.Model.SysUser)Session["UserInfo"];
        lblUser.Text = user.ReallyName + ",欢迎登录";
    }

    
       
       


    private void initMenu()
    {
        
        try
        {
            List<KeMei.Model.SysMenu> list = getMenuListByParentId(0);

            foreach (KeMei.Model.SysMenu c in list)
            {
                ExtAspNet.AccordionPane acdp1 = new ExtAspNet.AccordionPane();
                acdp1.Title = c.TName;
                acdp1.ShowBorder = false;
                acdp1.BodyPadding = "2px 5px";
                acdp1.Layout = ExtAspNet.Layout.Fit;

                Accordion1.Panes.Add(acdp1);

                ExtAspNet.Tree tree = new ExtAspNet.Tree();
                tree.ShowHeader = false;
                tree.ShowBorder = false;
                tree.EnableArrows = true;
                acdp1.Items.Add(tree);

                List<KeMei.Model.SysMenu> list2 = getMenuListByParentId(c.ID);

                foreach (KeMei.Model.SysMenu d in list2)
                {
                    ExtAspNet.TreeNode node = new ExtAspNet.TreeNode();
                    node.Text = d.TName;
                    node.NavigateUrl = d.LinkUrl;
                    node.Leaf = true;
                    node.Target = "main";
                    tree.Nodes.Add(node);
                }    

            }



        }
        catch (Exception ex)
        {
            KeMei.Common.MessageBox.Show(this, ex.ToString());
        }

    }


    private List<KeMei.Model.SysMenu> getMenuListByParentId(int parentID)
    {
        KeMei.BLL.SysMenu bll = new KeMei.BLL.SysMenu();
        List<KeMei.Model.SysMenu> list = null;
        List<KeMei.Model.SysMenu> result=null;
        try
        {
            list = bll.GetListByRoleID(int.Parse(Session["RoleID"].ToString()));

            IEnumerable<KeMei.Model.SysMenu> lst = from c in list
                                                      where c.ParentID == parentID
                                                      select c;

            result = lst.ToList<KeMei.Model.SysMenu>();
        }
        catch (Exception ex)
        {

            KeMei.Common.MessageBox.Show(this, ex.Message);
        }
        return result;
    }




}

